package com.ellricky.excute_president.ui.activity.school

import android.os.Bundle
import android.view.View
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.http.callback.EListCallback
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.excute_president.API_MONTH_PRICE
import com.ellricky.excute_president.API_YEAR_PRICE
import com.ellricky.excute_president.IncomeAdapter
import com.ellricky.excute_president.IncomeEntity

class IncomeFragment : BaseRefreshFragment<Void, BasePresenter<Void>, IncomeEntity>() {


    private var month: Boolean = true
    private var param: String = ""

    companion object {
        fun newInstance(month: Boolean, param: String): IncomeFragment {
            val fragment = IncomeFragment()
            val bundle = Bundle()
            bundle.putBoolean("month", month)
            bundle.putString("param", param)
            fragment.arguments = bundle
            return fragment
        }
    }

    override fun initUIView(view: View?) {
        super.initUIView(view)
        hideToolBar()
        month = arguments?.getBoolean("month", true) ?: true
        param = arguments?.getString("param") ?: ""
    }

    override fun getRvAdapter(): BaseRecyclerAdapter<IncomeEntity> {
        return IncomeAdapter()
    }

    override fun getResponseCallback(): BaseCallback {
        return object : EListCallback<IncomeEntity>(mContext) {
            override fun onSuccess(data: MutableList<IncomeEntity>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }

            override fun onErrorCode(code: String?, msg: String?) {
                super.onErrorCode(code, msg)
                rvView.onRefreshFailed(refresh)
            }

            override fun onHttpError(code: String?, msg: String?) {
                super.onHttpError(code, msg)
                rvView.onRefreshFailed(refresh)
            }
        }
    }

    override fun getUrlPath(): String {
        return if (month) API_MONTH_PRICE else API_YEAR_PRICE
    }

}
